package com.xo.xodemo.controller.dydatareception;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xo.xodemo.common.Result;
import com.xo.xodemo.mapper.db2.JiangshiMapper;
import com.xo.xodemo.springsecurityconfig.CustomUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

@Controller
@RequestMapping("/dydatareception")
public class dydatareceptionController {
    @Autowired
    JiangshiMapper jiangshiMapper;
    @RequestMapping ("/jiangshi")
    @ResponseBody
    public Result jiangshi(@RequestParam("page") Integer page, @RequestParam("limit")Integer limit, @RequestParam( value = "name", defaultValue="")String name, @RequestParam( value = "createTime",defaultValue = "")String createTime, @RequestParam(value = "telephone",defaultValue = "")String telephone) throws IOException {
        PageHelper.startPage(page,limit);
        PageInfo pageInfo=new PageInfo(jiangshiMapper.findalldy(name,createTime,telephone,""));
        return   Result.success( pageInfo);
    }
    @RequestMapping ("/jiangshioutside")
    @ResponseBody
    public Result jiangshioutside(@RequestParam("page") Integer page, @RequestParam("limit")Integer limit, @RequestParam( value = "name", defaultValue="")String name, @RequestParam( value = "createTime",defaultValue = "")String createTime, @RequestParam(value = "telephone",defaultValue = "")String telephone,@AuthenticationPrincipal CustomUserDetails userDetails) throws IOException {
        PageHelper.startPage(page,limit);
        PageInfo pageInfo=new PageInfo(jiangshiMapper.findalldy(name,createTime,telephone,"1"));
        return   Result.success( pageInfo);
    }
    @RequestMapping ("/jiangshiname")
    @ResponseBody
    public Result jiangshiname() throws IOException {
        return   Result.success(jiangshiMapper.findallname());
    }
    @RequestMapping ("/outsidejiangshiname")
    @ResponseBody
    public Result outsidejiangshiname() throws IOException {
        return   Result.success(jiangshiMapper.findoutsidename());
    }
}
